package com.lc202310;

import java.util.*;

/**
 * Description:
 *
 * @Create 2023/10/11 19:33
 * @Version 1.0
 */
public class Solution2512 {
    public List<Integer> topStudents(String[] positive_feedback, String[] negative_feedback, String[] report, int[] student_id, int k) {
        Set<String> positive = new HashSet<>(Arrays.asList(positive_feedback));
        Set<String> negative = new HashSet<>(Arrays.asList(negative_feedback));
        int length = student_id.length;
        int[] score = new int[length];

        for (int i = 0; i < length; i++) {
            String[] words = report[i].split(" ");
            for (String word : words) {
                if (positive.contains(word)) {
                    score[i] += 3;
                    continue;
                }
                if (negative.contains(word)) {
                    score[i] -= 1;
                }
            }
        }

        int tmpId, tmpScore;

        for (int i = 0; i < k; i++) {
            for (int j = i + 1; j < length; j++) {
                if (score[i] > score[j]) {
                    continue;
                }
                if (score[i] < score[j]) {
                    tmpId = student_id[i];
                    tmpScore = score[i];
                    student_id[i] = student_id[j];
                    student_id[j] = tmpId;
                    score[i] = score[j];
                    score[j] = tmpScore;
                    continue;
                }
                if(student_id[i] > student_id[j]){
                    tmpId = student_id[i];
                    tmpScore = score[i];
                    student_id[i] = student_id[j];
                    student_id[j] = tmpId;
                    score[i] = score[j];
                    score[j] = tmpScore;
                }
            }
        }
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < k; i++) {
            res.add(student_id[i]);
        }

        return res;
    }
}
